//
//  MDeviceSwitchingViewController.m
//  Mask
//
//  Created by 郭子一 on 2020/10/2.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MDeviceSwitchingViewController.h"
#import "MDeviceSwitchCell.h"
#import "MAddDeviceViewController.h"
@interface MDeviceSwitchingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MDeviceSwitchingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.showNavView = YES;
    self.navTitleLab.text = @"设备切换";
    [self makeUI];
}

- (void)makeUI
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kGScreenWidth, kGScreenHeight) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView registerClass:[MDeviceSwitchCell class] forCellReuseIdentifier:@"MDeviceSwitchCell"];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(self.navTitleLab.mas_bottom).offset(9);
        make.bottom.offset(-60);
    }];
    
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.bottom.offset(-10);
        make.height.mas_equalTo(45);
    }];
    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,kGScreenWidth - 30,45);
    gl.startPoint = CGPointMake(0.05, 0.1);
    gl.endPoint = CGPointMake(1, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:1/255.0 green:145/255.0 blue:254/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:195/255.0 blue:254/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    addBtn.layer.cornerRadius = 22.5;
    addBtn.layer.masksToBounds = YES;
    [addBtn.layer addSublayer:gl];
    [addBtn setTitle:@"添加设备" forState:UIControlStateNormal];
    [addBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateNormal];
    [addBtn.titleLabel setFont:JSS_FONT_5];
}

- (void)addBtnClick
{
    MAddDeviceViewController *vc = [[MAddDeviceViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
//    return self.titleArray.count;
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MDeviceSwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MDeviceSwitchCell"];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 120;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
